
import 'package:custom_pop_up_menu/custom_pop_up_menu.dart';
import 'package:flutter/cupertino.dart';
import 'package:yp/services/api.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import 'state.dart';

class MyWalletLogic extends GetxController {
  final state = MyWalletState();
  final pageController = PageController(viewportFraction: 1, keepPage: true);

  @override
  void onInit() {
    super.onInit();
    state.giftCardChoose = 0;
    state.giftCardArray = [{}];
    state.customController = CustomPopupMenuController();
    getWelfareCardList();
  }

  void onGiftCardClick(int index) {
    state.giftCardChoose = index;
    update();
  }

  /// 获取福利卡列表
  void getWelfareCardList() {
    Map<String, dynamic> params = {
      "use_platform": 2,
      "user_num_id:":SpUtil.getInt('empeNumId'),
      "card_status": 3,
      "access_token": SpUtil.getString('token'),
    };

    Api.getWelfareCardList(params).listen((event) {
      print("获取福利卡列表==========$event");
      if (event["code"] == 0) {
        if (event["available_cards"] != null) {
          state.giftCardArray = event["available_cards"];
          state.giftCardArray.add({});
        }
        if (event["valid_cards"] != null) {
          state.validCardsArray = event['valid_cards'];
          state.validCardsArray.add({});
        }
        state.walletBalance = event["total_available_amount"];
      }
      update();
    });
  }



}